From: | Tony Rolfe |
Date: | 19 Sep 99 at 08:16:27 |
Subject: | Re: Rounding amounts |
On Sun, 19 Sep 1999 02:34:32 +0100 Paul Burkey said:
> Tony Rolfe wrote:
> > Australia has no 1 or 2 cent coins, so cash amounts are rounded to
> > the nearest 5 cents.
> >
> > I have a long variable containing the number of cents and need to
> > round so numbers ending in 3,4,5,6 or 7 are converted to end in 5, all
> > others are to end in zero (1,2 rounded down, 8 & 9 rounded up)
> >
> > any elegant ideas anyone?
>
> This is a nice problem. I'm not 100% sure I've done exactly what you
> want but it does produce the same results that the other functions
> that have been proposed so far.
>
> for example:
>
> 1 = 0 2 = 0
> 3 = 5 4 = 5
> 5 = 5 6 = 5
> 7 = 5 8 = 10
> 9 = 10 10 = 10
> 11 = 10 12 = 10
> 13 = 15 14 = 15
> and so on...
>
>
> ; The function
>
> Function .l Round{cents.l}
> rounded.l = (cents/5)*5
> If (cents-rounded) > 2 Then rounded+5
> Function Return rounded
> End Function
>
> ; And to use
>
> rounded.l = Round{mycents.l}
>
>
>
>
> Elegant enough?
Lovely.
Thanks to all who have helped. Now I'll have to get my brain wrapped
around the alternatives.
Cheers
---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list-help@netsoc.ucd.ie